package uk.ac.salfordcc.sccmobile;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;

public class Home extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		
    	SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
		String storedUsername = sp.getString("USERNAME", ""); //returns "" if not stored.
		
		if (storedUsername == null || storedUsername.equals("")) {
			Log.e("SETTINGS","... need to record a username");
	    	Intent intent = new Intent(this, StoreCredentials.class);
	    	startActivity(intent);
		} else
		{
			Log.e("STORED USERNAME: ",storedUsername);			
		}
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.home, menu);
		return true;
	}

    public void openSMS(View view) {
    	Intent intent = new Intent(this, Sms.class);
    	startActivity(intent);
    }

    public void openSettings(View view) {
    	Intent intent = new Intent(this, StoreCredentials.class);
    	startActivity(intent);
    }	
}
